package org.example.msg.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/msg")
@RestController
public class MsgController {

    @Autowired
    private JavaMailSender javaMailSender;


    /**
     * 合同审核邮件推送功能
     * @param email
     * @param content
     * @throws Exception
     */
    @RequestMapping("/send")
    public  void send(String email,String content) throws Exception {
        sendEmail(email,"合同审核",content);
    }

    /**
     * 邮件通知
     * @param to
     * @param subject
     * @param content
     */
    private void sendEmail(String to, String subject, String content) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom("87941125@qq.com");
        message.setTo(to);
        message.setSubject(subject);
        message.setText(content);
        javaMailSender.send(message);
    }

}
